package org.dromara.study.controller;


import org.dromara.common.core.domain.R;
import org.dromara.study.domain.entity.Course;
import org.dromara.study.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/course")
@RestController
public class CourseController {

    @Autowired
    private CourseService courseService;

    @PostMapping("/add")
    public R<String> add(@RequestBody Course course){
        courseService.save(course);
        return R.ok("新增成功");
    }


    @PostMapping("/edit")
    public R<String> update(@RequestBody Course course){
        courseService.updateById(course);
        return R.ok("编辑成功");
    }

    @GetMapping("/remove/{id}")
    public R<String> remove(@PathVariable("id") Long id){
        courseService.removeById(id);
        return R.ok("删除成功");
    }

    @GetMapping("/list")
    public R<List<Course>> getList(Course course){
        return R.ok(courseService.list());
    }


}
